package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.Advertise;
import com.fantastic.service.zjs.AdvertiseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/2 21:58
 * @description: 广告信息表请求控制器
 */
@RestController
@RequestMapping("/advertise")
public class AdvertiseControllerAdmin {
    @Resource
    private AdvertiseService advertiseService;

    /**
     * 查询所有的广告信息
     *
     * @param advertise
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/listAdvertises")
    public ResultData listAdvertises(Advertise advertise, @RequestParam(name="page",
            defaultValue = "1") int pageNum,
                                     @RequestParam(name="limit",defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Advertise> advertises = advertiseService.listAdvertises(advertise);
        advertises.stream().forEach(System.out::println);
        PageInfo<Advertise> advertisePageInfo = new PageInfo<>(advertises);
        return new ResultData(RespStatusInfo.OK, advertisePageInfo);
    }

    /**
     * 查询单个广告信息
     *
     * @param advertiseId
     * @return
     */
    @GetMapping("/getAdvertise")
    public ResultData getAdvertise(Integer advertiseId) {
        return new ResultData(RespStatusInfo.OK, advertiseService.getAdvertise(advertiseId));
    }

    /**
     * 添加广告信息
     *
     * @param filePhoto
     * @param advertise
     * @return
     */
    @PostMapping("/insertAdvertise")
    public ResultData insertAdvertise(MultipartFile filePhoto, Advertise advertise) {
        return new ResultData(RespStatusInfo.OK, advertiseService.insertAdvertise(filePhoto, advertise));
    }

    /**
     * 修改广告信息
     *
     * @param filePhoto
     * @param advertise
     * @return
     */
    @PostMapping("/updateAdvertise")
    public ResultData updateAdvertise(MultipartFile filePhoto, Advertise advertise) {
        return new ResultData(RespStatusInfo.OK, advertiseService.updateAdvertise(filePhoto, advertise));
    }

    /**
     * 删除广告信息
     *
     * @param advertiseId
     * @return
     */
    @PostMapping("/deleteAdvertise")
    public ResultData deleteAdvertise(Integer advertiseId) {
        return new ResultData(RespStatusInfo.OK, advertiseService.deleteAdvertise(advertiseId));
    }


}
